﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WeiXinWeb.Models;
using WeiXinWeb.Server;
using WeiXinWeb.Filter;
using System.Web.Security;
using WeiXinWeb.Helper;

namespace WeiXinWeb.Controllers
{
    public class LoginController : Controller
    {
        //
        // GET: /Login/
        [FilterBrowser]
        public ActionResult Index()
        {
            var cc = new HelpCookies().GetCookiseInfo("tel");
            ViewBag.telmessage = cc;            
            return View();
        }

        public ActionResult BrowserError()
        {
            return View();
        }

        [HttpPost]
        public ActionResult LoginWX(TruckCompany model)                 
        {
            var initial = model.password;
            model.password = SimpleCrypt.Encode(model.password);
            var result = new TruckServer().VerifyLogin(model);
            var str = "";
            var data =new object();
            if (result)
            {
                new HelpCookies().SetCookise("tel", model.tel);
                FormsAuthentication.SetAuthCookie(model.tel,false);
                Helper.HelpCookies.CurrentUserObject = new TruckServer().GetSingleObject(model);
                data = new { message = "", def = initial == "123456" ? true : false };
                return Json(data, JsonRequestBehavior.AllowGet);
            }
            else
            {
                data = new { message = "手机号或密码不正确,请从新输入！", def = false };
                return Json(data,JsonRequestBehavior.AllowGet);
            }
                
        }

    }
}
